/*
 * @Description: 管理员管理数据规则
 * @Author: HuiSir<273250950@qq.com>
 * @Date: 2021-09-02 15:39:43
 * @LastEditTime: 2025-08-30 16:34:40
 */
import { useProjectConfig, rules2MockMethods } from "./_helpers";
import Mockjs from "mockjs";
import permissionList from "./_permList";
const project = useProjectConfig();
const { Random } = Mockjs;
const Prefix = "/admin/";

export const adminInfo = {
  id: "@id",
  accountNo: "@name",
  name: "@cname",
  type: '@pick(["S", "G"])', //S:超级管理 G:普通管理
  sex: '@pick(["M", "F"])',
  email: "@email",
  phone: /^(13[0-9]|14[57]|15[0-9]|18[0-35-9])\d{8}$/,
  status: 1, //1-正常；0-停用
  headImg: Random.image("50x50", "#2f3447", "#FFF", "A"), // 头像
  roleIds: ["001", "002", "003"],
  roles: [{ name: "角色1" }, { name: "角色2" }], // 角色所有信息
  deptId: "002", // 部门ID
  dept: {
    id: "002",
    name: "行政部",
    status: "@integer(0, 1)",
    leader: "@cname",
    email: "@email",
    phone: /^(13[0-9]|14[57]|15[0-9]|18[0-35-9])\d{8}$/,
    delFlag: "@integer(0, 1)",
    remark: "",
    pid: null,
    createTime: "@datetime",
    updateTime: "@datetime",
    createUser: "@name",
    updateUser: "@name",
  },
  permissionList, // 权限树结构
  createTime: "@datetime",
  updateTime: "@datetime",
  createUser: "@name",
  updateUser: "@name",
};

// 管理员信息
export const current = {
  [project.responseFields.data]: adminInfo,
};

// 登出
const exit = { [project.responseFields.message]: "注销登陆成功" };

// 重设密码
const updatePassword = { [project.responseFields.message]: "修改密码成功" };

// 重置密码
const initPassword = { [project.responseFields.message]: "密码已重置" };

// 查询所有管理员列表（用于管理员管理）
const query = {
  [project.responseFields.data]: {
    [`${project.responseDataSubFields.records}|15`]: [adminInfo],
    page: 1,
    limit: 10,
    [project.responseDataSubFields.total]: 100,
    pageSize: 10,
  },
};

// 更新管理员信息
const add = { [project.responseFields.message]: "新增成功" };

// 更新管理员信息
const update = { [project.responseFields.message]: "保存成功" };

// 删除账号(删除单个、多个)
const deleteUser = { [project.responseFields.message]: "删除成功" };

const Rules: Record<string, unknown> = {
  add,
  current,
  exit,
  updatePassword,
  query,
  update,
  delete: deleteUser,
  initPassword,
};

export default rules2MockMethods(Rules, Prefix);
